package priv.pront.code.national.acwing.base;

import java.util.Scanner;

public class 全排列2 {
    static int[] a;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        a = new int[n];
        for(int i = 0; i < n; i++) a[i] = i + 1;
        dfs(0);
    }
    private static void dfs(int i){
        if (i == a.length) {
            for(int c : a) System.out.print(c + " ");
            System.out.println();
            return;
        }
        for(int k = i; k < a.length; k++){
            swap(i,k);
            dfs(i + 1);
            swap(i,k);
        }
    }

    private static void swap(int i, int j) {
        int tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
    }
}
